<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0,viewport-fit=cover"><title>JDBC | Xuan的博客</title><meta name="author" content="Xuan"><meta name="copyright" content="Xuan"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="JDBCJDBC是什么?Java DataBase Connectivity，提供了一套API，可在不修改代码的前提下操作不同的数据库 接口包括两个层面：  面向应用的API，开发人员使用 DriverManager 管理驱动程序 Connection 连接数据库 Statement 执行数据库语句 ResultSet 收集执行结果   面向数据库开发商的API，供数据库厂商（驱动）调用  JDB">
<meta property="og:type" content="article">
<meta property="og:title" content="JDBC">
<meta property="og:url" content="http://leesmile.gitee.io/smile/2023/06/09/Java/JDBC/index.html">
<meta property="og:site_name" content="Xuan的博客">
<meta property="og:description" content="JDBCJDBC是什么?Java DataBase Connectivity，提供了一套API，可在不修改代码的前提下操作不同的数据库 接口包括两个层面：  面向应用的API，开发人员使用 DriverManager 管理驱动程序 Connection 连接数据库 Statement 执行数据库语句 ResultSet 收集执行结果   面向数据库开发商的API，供数据库厂商（驱动）调用  JDB">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://gitee.com/leesmile/image-host/raw/master/images/202310201611606.jpg">
<meta property="article:published_time" content="2023-06-09T01:53:46.000Z">
<meta property="article:modified_time" content="2023-06-09T01:53:46.000Z">
<meta property="article:author" content="Xuan">
<meta property="article:tag" content="Java">
<meta property="article:tag" content="MySQL">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://gitee.com/leesmile/image-host/raw/master/images/202310201611606.jpg"><link rel="shortcut icon" href="/smile/img/favicon.png"><link rel="canonical" href="http://leesmile.gitee.io/smile/2023/06/09/Java/JDBC/index.html"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="stylesheet" href="/smile/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox/fancybox.min.css" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = {
  root: '/smile/',
  algolia: undefined,
  localSearch: undefined,
  translate: undefined,
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":false},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '',
  dateSuffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: undefined,
  lightbox: 'fancybox',
  Snackbar: undefined,
  source: {
    justifiedGallery: {
      js: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery/dist/fjGallery.min.js',
      css: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery/dist/fjGallery.min.css'
    }
  },
  isPhotoFigcaption: false,
  islazyload: false,
  isAnchor: false,
  percent: {
    toc: true,
    rightside: false,
  },
  autoDarkmode: false
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: 'JDBC',
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2023-06-09 09:53:46'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(win=>{
    win.saveToLocal = {
      set: function setWithExpiry(key, value, ttl) {
        if (ttl === 0) return
        const now = new Date()
        const expiryDay = ttl * 86400000
        const item = {
          value: value,
          expiry: now.getTime() + expiryDay,
        }
        localStorage.setItem(key, JSON.stringify(item))
      },

      get: function getWithExpiry(key) {
        const itemStr = localStorage.getItem(key)

        if (!itemStr) {
          return undefined
        }
        const item = JSON.parse(itemStr)
        const now = new Date()

        if (now.getTime() > item.expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return item.value
      }
    }
  
    win.getScript = url => new Promise((resolve, reject) => {
      const script = document.createElement('script')
      script.src = url
      script.async = true
      script.onerror = reject
      script.onload = script.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        script.onload = script.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(script)
    })
  
    win.getCSS = (url,id = false) => new Promise((resolve, reject) => {
      const link = document.createElement('link')
      link.rel = 'stylesheet'
      link.href = url
      if (id) link.id = id
      link.onerror = reject
      link.onload = link.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        link.onload = link.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(link)
    })
  
      win.activateDarkMode = function () {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = function () {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
          if (t === 'dark') activateDarkMode()
          else if (t === 'light') activateLightMode()
        
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    
    const detectApple = () => {
      if(/iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)){
        document.documentElement.classList.add('apple')
      }
    }
    detectApple()
    })(window)</script><link rel="stylesheet" href="/css/font.css" media="defer" onload="this.media='all'"><link rel="stylesheet" href="/css/custom.css" media="defer" onload="this.media='all'"><link rel="stylesheet" href="/css/whiteLine.css" media="defer" onload="this.media='all'"><link rel="stylesheet" href="/css/progress_bar.css" media="defer" onload="this.media='all'"><link rel="stylesheet" href="/css/cat.css"><link rel="stylesheet" href="/css/readPercent.css"><link rel="stylesheet" href="https://cdn1.tianli0.top/npm/element-ui@2.15.6/packages/theme-chalk/lib/index.css"><div id="myscoll"></div><!-- hexo injector head_end start --><link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/Zfour/Butterfly-double-row-display@1.00/cardlistpost.min.css"/>
<style>#recent-posts > .recent-post-item >.recent-post-info > .article-meta-wrap > .tags:before {content:"\A";
  white-space: pre;}#recent-posts > .recent-post-item >.recent-post-info > .article-meta-wrap > .tags > .article-meta__separator{display:none}</style>
<link rel="stylesheet" href="https://npm.elemecdn.com/hexo-butterfly-footer-beautify@1.0.0/lib/runtime.css" media="print" onload="this.media='all'"><!-- hexo injector head_end end --><meta name="generator" content="Hexo 6.3.0"></head><body><div id="web_bg"></div><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src="https://leesmile.gitee.io/smile/img/avatarImg.bmp" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="sidebar-site-data site-data is-center"><a href="/smile/archives/"><div class="headline">文章</div><div class="length-num">142</div></a><a href="/smile/tags/"><div class="headline">标签</div><div class="length-num">36</div></a><a href="/smile/categories/"><div class="headline">分类</div><div class="length-num">32</div></a></div><hr class="custom-hr"/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/smile/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/smile/archives/"><i class="fa-fw fas fa-archive"></i><span> 文章</span></a></div><div class="menus_item"><a class="site-page" href="/smile/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/smile/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div></div></div></div><div class="post" id="body-wrap"><header class="post-bg" id="page-header" style="background-image: url('https://gitee.com/leesmile/image-host/raw/master/images/202310201611606.jpg')"><nav id="nav"><span id="blog-info"><a href="/smile/" title="Xuan的博客"><span class="site-name">Xuan的博客</span></a></span><div id="menus"><div class="menus_items"><div class="menus_item"><a class="site-page" href="/smile/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/smile/archives/"><i class="fa-fw fas fa-archive"></i><span> 文章</span></a></div><div class="menus_item"><a class="site-page" href="/smile/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/smile/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div></div><div id="nav-right"><a class="meihua faa-parent animated-hover" onclick="toggleWinbox()" title="美化设置-自定义你的风格" id="meihua-button"><svg class="faa-tada icon" style="height:26px;width:26px;fill:currentColor;position:relative;top:8px" aria-hidden="true"><use xlink:href="#icon-tupian1"></use></svg></a><a class="sun_moon faa-parent animated-hover" onclick="switchNightMode()" title="浅色和深色模式转换" id="nightmode-button"><svg class="faa-tada" style="height:25px;width:25px;fill:currentColor;position:relative;top:7px" viewBox="0 0 1024 1024"><use id="modeicon" xlink:href="#icon-moon"></use></svg></a></div><div id="toggle-menu"><a class="site-page" href="javascript:void(0);"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="post-info"><h1 class="post-title">JDBC</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2023-06-09T01:53:46.000Z" title="发表于 2023-06-09 09:53:46">2023-06-09</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2023-06-09T01:53:46.000Z" title="更新于 2023-06-09 09:53:46">2023-06-09</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/smile/categories/Java/">Java</a><i class="fas fa-angle-right post-meta-separator"></i><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/smile/categories/Java/MySQL/">MySQL</a></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-pv-cv" id="" data-flag-title="JDBC"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">阅读量:</span><span id="busuanzi_value_page_pv"><i class="fa-solid fa-spinner fa-spin"></i></span></span></div></div></div><section class="main-hero-waves-area waves-area"><svg class="waves-svg" xmlns="http://www.w3.org/2000/svg" xlink="http://www.w3.org/1999/xlink" viewBox="0 24 150 28" preserveAspectRatio="none" shape-rendering="auto"><defs><path id="gentle-wave" d="M -160 44 c 30 0 58 -18 88 -18 s 58 18 88 18 s 58 -18 88 -18 s 58 18 88 18 v 44 h -352 Z"></path></defs><g class="parallax"><use href="#gentle-wave" x="48" y="0"></use><use href="#gentle-wave" x="48" y="3"></use><use href="#gentle-wave" x="48" y="5"></use><use href="#gentle-wave" x="48" y="7"></use></g></svg></section><div id="post-top-cover"><img class="nolazyload" id="post-top-bg" src="background-image: url('https://gitee.com/leesmile/image-host/raw/master/images/202310201611606.jpg')"></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><h1 id="JDBC"><a href="#JDBC" class="headerlink" title="JDBC"></a>JDBC</h1><h4 id="JDBC是什么"><a href="#JDBC是什么" class="headerlink" title="JDBC是什么?"></a>JDBC是什么?</h4><p>Java DataBase Connectivity，提供了一套API，可在不修改代码的前提下操作不同的数据库</p>
<p>接口包括两个层面：</p>
<ol>
<li>面向应用的API，开发人员使用<ol>
<li>DriverManager 管理驱动程序</li>
<li>Connection 连接数据库</li>
<li>Statement 执行数据库语句</li>
<li>ResultSet 收集执行结果</li>
</ol>
</li>
<li>面向数据库开发商的API，供数据库厂商（驱动）调用</li>
</ol>
<h4 id="JDBC访问数据库过程"><a href="#JDBC访问数据库过程" class="headerlink" title="JDBC访问数据库过程"></a>JDBC访问数据库过程</h4><ol>
<li>加载数据库驱动</li>
<li>获取Connection，一次连接</li>
<li>通过Statement执行sql语句</li>
<li>通过ResultSet获取执行结果</li>
</ol>
<h4 id="封装JDBCUtil的过程"><a href="#封装JDBCUtil的过程" class="headerlink" title="封装JDBCUtil的过程"></a>封装JDBCUtil的过程</h4><p>加载驱动，获取连接，释放资源的过程</p>
<p>JDBCUtil</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> com.example;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> java.sql.*;</span><br><span class="line"></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">JDBCUtil</span> &#123;</span><br><span class="line">    <span class="keyword">static</span>&#123;</span><br><span class="line">        <span class="comment">//  加载驱动</span></span><br><span class="line">        <span class="keyword">try</span> &#123;</span><br><span class="line">            Class.forName(<span class="string">&quot;com.mysql.cj.jdbc.Driver&quot;</span>);</span><br><span class="line">        &#125; <span class="keyword">catch</span> (ClassNotFoundException e) &#123;</span><br><span class="line">            <span class="keyword">throw</span> <span class="keyword">new</span> <span class="title class_">RuntimeException</span>(e);</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="comment">// 获取连接</span></span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">static</span> Connection <span class="title function_">getConnection</span><span class="params">()</span> <span class="keyword">throws</span> ClassNotFoundException, SQLException &#123;</span><br><span class="line">        <span class="type">Connection</span> <span class="variable">connection</span> <span class="operator">=</span> <span class="literal">null</span>;</span><br><span class="line">        <span class="keyword">try</span> &#123;</span><br><span class="line">                    <span class="comment">// 获取连接</span></span><br><span class="line">            <span class="type">String</span> <span class="variable">url</span> <span class="operator">=</span> <span class="string">&quot;jdbc:mysql://127.0.0.1:3306/test&quot;</span>;</span><br><span class="line">            <span class="type">String</span> <span class="variable">user</span> <span class="operator">=</span> <span class="string">&quot;root&quot;</span>;</span><br><span class="line">            <span class="type">String</span> <span class="variable">pwd</span> <span class="operator">=</span> <span class="string">&quot;123456&quot;</span>;</span><br><span class="line">            connection = DriverManager.getConnection(url, user, pwd);</span><br><span class="line">        &#125;<span class="keyword">catch</span> (Exception e)&#123;</span><br><span class="line">            e.printStackTrace();</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">return</span> connection;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="comment">// 释放资源</span></span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title function_">release</span><span class="params">(Connection connection, Statement statement, ResultSet resultSet)</span> <span class="keyword">throws</span> SQLException &#123;</span><br><span class="line">        <span class="keyword">if</span> (connection!= <span class="literal">null</span>)&#123;</span><br><span class="line">            connection.close();</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">if</span> (statement!= <span class="literal">null</span>)&#123;</span><br><span class="line">            statement.close();</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">if</span> (resultSet!= <span class="literal">null</span>)&#123;</span><br><span class="line">            resultSet.close();</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h4 id="实现对数据库的增删改查"><a href="#实现对数据库的增删改查" class="headerlink" title="实现对数据库的增删改查"></a>实现对数据库的增删改查</h4><ol>
<li><p>创建Statement对象</p>
<p>可以使用connection.createStatement()创建对象执行sql</p>
<p>而connection.createprepareStatement()则可以通过预编译的方式，传入可变的参数实现动态sql</p>
</li>
<li><p>设置动态sql参数</p>
<p>对预编译的prepareStatement使用setString(1,name)，set参数类型(位置，值)</p>
</li>
<li><p>执行sql语句</p>
<p>executeQuery和executeUpdate分别表示执行查询语句和执行增删改的语句</p>
</li>
<li><p>接受执行结果</p>
<p>executeQuery返回的值可以通过ResultSet接受，通过getMetaData获取后再通过迭代器循环取出结果（非常麻烦）</p>
<p>executeUpdate的返回值为int类型，指更新执行的数据行数</p>
</li>
</ol>
<p>增删改查测试类</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> com.example;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> java.math.BigDecimal;</span><br><span class="line"><span class="keyword">import</span> java.sql.*;</span><br><span class="line"></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">main</span> &#123;</span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title function_">main</span><span class="params">(String[] args)</span> <span class="keyword">throws</span> ClassNotFoundException, SQLException &#123;</span><br><span class="line">        transaction(<span class="number">97.3F</span>,<span class="number">2.7F</span>);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title function_">Query</span><span class="params">()</span> <span class="keyword">throws</span> SQLException, ClassNotFoundException &#123;</span><br><span class="line">        <span class="type">Connection</span> <span class="variable">connection</span> <span class="operator">=</span> JDBCUtil.getConnection();</span><br><span class="line">        <span class="comment">// 定义SQL</span></span><br><span class="line">        <span class="type">String</span> <span class="variable">sql</span> <span class="operator">=</span> <span class="string">&quot;select * from account limit 1&quot;</span>;</span><br><span class="line">        <span class="type">Statement</span> <span class="variable">statement</span> <span class="operator">=</span> connection.createStatement();</span><br><span class="line">        <span class="type">ResultSet</span> <span class="variable">resultSet</span> <span class="operator">=</span> statement.executeQuery(sql);</span><br><span class="line">        <span class="type">ResultSetMetaData</span> <span class="variable">resultSetMetaData</span> <span class="operator">=</span> resultSet.getMetaData();</span><br><span class="line">        <span class="comment">// 目标数据库的列信息</span></span><br><span class="line"><span class="comment">//        int columnCount = resultSetMetaData.getColumnCount();</span></span><br><span class="line"><span class="comment">//        for (int i = 1; i &lt; columnCount; i++) &#123;</span></span><br><span class="line"><span class="comment">//            String columnName = resultSetMetaData.getColumnName(i);</span></span><br><span class="line"><span class="comment">//            String typeName  = resultSetMetaData.getColumnTypeName(i);</span></span><br><span class="line"><span class="comment">//            System.out.println(columnName + typeName);</span></span><br><span class="line"><span class="comment">//        &#125;</span></span><br><span class="line">        <span class="comment">// 获取行信息</span></span><br><span class="line">        <span class="keyword">while</span> (resultSet.next()) &#123;</span><br><span class="line">            <span class="type">BigDecimal</span> <span class="variable">id</span> <span class="operator">=</span> resultSet.getBigDecimal(<span class="string">&quot;id_&quot;</span>);</span><br><span class="line">            <span class="type">String</span> <span class="variable">kpdwmc</span> <span class="operator">=</span> resultSet.getString(<span class="string">&quot;kpdwmc_&quot;</span>);</span><br><span class="line">            System.out.println(id + <span class="string">&quot;\n&quot;</span> + kpdwmc);</span><br><span class="line">        &#125;</span><br><span class="line">        JDBCUtil.release(connection,statement,resultSet);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title function_">add</span><span class="params">(String name, Integer age)</span> <span class="keyword">throws</span> SQLException, ClassNotFoundException &#123;</span><br><span class="line">        <span class="type">Connection</span> <span class="variable">connection</span> <span class="operator">=</span> JDBCUtil.getConnection();</span><br><span class="line">        <span class="type">String</span> <span class="variable">sql</span> <span class="operator">=</span> <span class="string">&quot;insert into account(name,money) values (?,?)&quot;</span>;</span><br><span class="line">        <span class="type">PreparedStatement</span> <span class="variable">statement</span> <span class="operator">=</span> connection.prepareStatement(sql);</span><br><span class="line">        <span class="comment">// 通过statement.setxxx来实现动态sql</span></span><br><span class="line">        statement.setString(<span class="number">1</span>, name);</span><br><span class="line">        statement.setInt(<span class="number">2</span>, age);</span><br><span class="line">        <span class="type">int</span> <span class="variable">i</span> <span class="operator">=</span> statement.executeUpdate();</span><br><span class="line">        System.out.println(i);</span><br><span class="line">        JDBCUtil.release(connection,statement,<span class="literal">null</span>);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title function_">update</span><span class="params">(Integer je,Integer dj,BigDecimal id)</span> <span class="keyword">throws</span> SQLException, ClassNotFoundException &#123;</span><br><span class="line">        <span class="type">Connection</span> <span class="variable">connection</span> <span class="operator">=</span> JDBCUtil.getConnection();</span><br><span class="line">        <span class="type">String</span> <span class="variable">sql</span> <span class="operator">=</span> <span class="string">&quot;update account set je_ = ? ,dj = ? where id = ?&quot;</span>;</span><br><span class="line">        <span class="type">PreparedStatement</span> <span class="variable">statement</span> <span class="operator">=</span> connection.prepareStatement(sql);</span><br><span class="line">        statement.setInt(<span class="number">1</span>, je);</span><br><span class="line">        statement.setInt(<span class="number">2</span>, dj);</span><br><span class="line">        statement.setBigDecimal(<span class="number">3</span>,id);</span><br><span class="line">        <span class="type">int</span> <span class="variable">i</span> <span class="operator">=</span> statement.executeUpdate();</span><br><span class="line">        System.out.println(i);</span><br><span class="line">        JDBCUtil.release(connection,statement,<span class="literal">null</span>);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title function_">delete</span><span class="params">(BigDecimal id)</span> <span class="keyword">throws</span> SQLException, ClassNotFoundException &#123;</span><br><span class="line">        <span class="type">Connection</span> <span class="variable">connection</span> <span class="operator">=</span> JDBCUtil.getConnection();</span><br><span class="line">        <span class="type">String</span> <span class="variable">sql</span> <span class="operator">=</span> <span class="string">&quot;DELETE from account where id =?&quot;</span>;</span><br><span class="line">        <span class="type">PreparedStatement</span> <span class="variable">statement</span> <span class="operator">=</span> connection.prepareStatement(sql);</span><br><span class="line">        statement.setBigDecimal(<span class="number">1</span>,id);</span><br><span class="line">        <span class="type">int</span> <span class="variable">i</span> <span class="operator">=</span> statement.executeUpdate();</span><br><span class="line">        System.out.println(i);</span><br><span class="line">        JDBCUtil.release(connection,statement,<span class="literal">null</span>);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h4 id="使用数据库事务"><a href="#使用数据库事务" class="headerlink" title="使用数据库事务"></a>使用数据库事务</h4><ol>
<li>先通过setAutoCommit(false)将连接的自动提交关闭</li>
<li>在try代码块中执行sql语句，如果失败了则在catch中调用connection.rollback();回滚事务</li>
<li>最后若正常执行则通过connection.commit()提交事务</li>
</ol>
<p>更新事务</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> com.example;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> java.math.BigDecimal;</span><br><span class="line"><span class="keyword">import</span> java.sql.*;</span><br><span class="line"></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">main</span> &#123;</span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title function_">main</span><span class="params">(String[] args)</span> <span class="keyword">throws</span> ClassNotFoundException, SQLException &#123;</span><br><span class="line">        transaction(<span class="number">97.3F</span>,<span class="number">2.7F</span>);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="comment">// 事务</span></span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title function_">transaction</span><span class="params">(Float je,Float se)</span> <span class="keyword">throws</span> SQLException, ClassNotFoundException &#123;</span><br><span class="line">        <span class="type">Connection</span> <span class="variable">connection</span> <span class="operator">=</span> JDBCUtil.getConnection();</span><br><span class="line">        connection.setAutoCommit(<span class="literal">false</span>);</span><br><span class="line">        <span class="type">String</span> <span class="variable">sql1</span> <span class="operator">=</span> <span class="string">&quot;UPDATE account set je_ = ?,se_ = ? where id_ = 607083544107974656&quot;</span>;</span><br><span class="line">        <span class="type">String</span> <span class="variable">sql2</span> <span class="operator">=</span> <span class="string">&quot;UPDATE account set je_ = ?,se_ = ? where id_ = 607083549719953408&quot;</span>;</span><br><span class="line">        <span class="type">PreparedStatement</span> <span class="variable">statement1</span> <span class="operator">=</span> connection.prepareStatement(sql1);</span><br><span class="line">        <span class="type">PreparedStatement</span> <span class="variable">statement2</span> <span class="operator">=</span> connection.prepareStatement(sql2);</span><br><span class="line">        statement1.setFloat(<span class="number">1</span>,je);</span><br><span class="line">        statement1.setFloat(<span class="number">2</span>,se);</span><br><span class="line">        statement2.setFloat(<span class="number">1</span>,je);</span><br><span class="line">        statement2.setFloat(<span class="number">2</span>,se);</span><br><span class="line">        <span class="keyword">try</span>&#123;</span><br><span class="line">            statement1.executeUpdate();</span><br><span class="line">            <span class="type">int</span> <span class="variable">i</span> <span class="operator">=</span> <span class="number">10</span>/<span class="number">0</span>;</span><br><span class="line">            statement2.executeUpdate();</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">catch</span> (Exception e)&#123;</span><br><span class="line">            <span class="comment">// 回滚</span></span><br><span class="line">            connection.rollback();</span><br><span class="line">            System.out.println(<span class="string">&quot;执行失败，回滚&quot;</span>);</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="comment">// 提交</span></span><br><span class="line">        connection.commit();</span><br><span class="line">        JDBCUtil.release(connection,statement1,<span class="literal">null</span>);</span><br><span class="line">        JDBCUtil.release(connection,statement2,<span class="literal">null</span>);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></article><div class="post-copyright"><div class="post-copyright__title"><span class="post-copyright-info"><h>JDBC</h></span></div><div class="post-copyright__type"><span class="post-copyright-info"><a href="http://leesmile.gitee.io/smile/2023/06/09/Java/JDBC/">http://leesmile.gitee.io/smile/2023/06/09/Java/JDBC/</a></span></div><div class="post-copyright-m"><div class="post-copyright-m-info"><div class="post-copyright-a"><h>作者</h><div class="post-copyright-cc-info"><h>Xuan</h></div></div><div class="post-copyright-c"><h>发布于</h><div class="post-copyright-cc-info"><h>2023-06-09</h></div></div><div class="post-copyright-u"><h>更新于</h><div class="post-copyright-cc-info"><h>2023-06-09</h></div></div><div class="post-copyright-c"><h>许可协议</h><div class="post-copyright-cc-info"><a class="icon" rel="noopener" target="_blank" title="Creative Commons" href="https://creativecommons.org/"><i class="fab fa-creative-commons"></i></a><a rel="noopener" target="_blank" title="CC BY-NC-SA 4.0" href="https://creativecommons.org/licenses/by-nc-sa/4.0/">CC BY-NC-SA 4.0</a></div></div></div></div></div><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/smile/tags/Java/">Java</a><a class="post-meta__tags" href="/smile/tags/MySQL/">MySQL</a></div><div class="post_share"><div class="social-share" data-image="https://gitee.com/leesmile/image-host/raw/master/images/202310201611606.jpg" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/butterfly-extsrc/sharejs/dist/css/share.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/sharejs/dist/js/social-share.min.js" defer></script></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/smile/2023/06/09/Java/DbUtil/" title="DbUtil"><img class="cover" src="https://gitee.com/leesmile/image-host/raw/master/images/202310201611606.jpg" onerror="onerror=null;src='/smile/img/404.jpg'" alt="cover of previous post"><div class="pagination-info"><div class="label">上一篇</div><div class="prev_info">DbUtil</div></div></a></div><div class="next-post pull-right"><a href="/smile/2023/06/09/Java/%E6%95%B0%E6%8D%AE%E5%BA%93%E8%BF%9E%E6%8E%A5%E6%B1%A0/" title="数据库连接池"><img class="cover" src="https://gitee.com/leesmile/image-host/raw/master/images/202310201611606.jpg" onerror="onerror=null;src='/smile/img/404.jpg'" alt="cover of next post"><div class="pagination-info"><div class="label">下一篇</div><div class="next_info">数据库连接池</div></div></a></div></nav><div class="relatedPosts"><div class="headline"><i class="fas fa-thumbs-up fa-fw"></i><span>相关推荐</span></div><div class="relatedPosts-list"><div><a href="/smile/2023/06/09/Java/DbUtil/" title="DbUtil"><img class="cover" src="https://gitee.com/leesmile/image-host/raw/master/images/202310201611606.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2023-06-09</div><div class="title">DbUtil</div></div></a></div><div><a href="/smile/2023/06/09/Java/%E6%95%B0%E6%8D%AE%E5%BA%93%E8%BF%9E%E6%8E%A5%E6%B1%A0/" title="数据库连接池"><img class="cover" src="https://gitee.com/leesmile/image-host/raw/master/images/202310201611606.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2023-06-09</div><div class="title">数据库连接池</div></div></a></div><div><a href="/smile/2023/10/08/Java/IDEA%E7%9A%84TODO%E7%94%A8%E6%B3%95/" title="IDEA的TODO用法"><img class="cover" src="https://gitee.com/leesmile/image-host/raw/master/images/202310201611986.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2023-10-08</div><div class="title">IDEA的TODO用法</div></div></a></div><div><a href="/smile/2024/01/02/Java/Java%E5%B9%B3%E5%8F%B0%E7%9A%84%E7%89%B9%E6%80%A7/" title="Java平台的特性"><img class="cover" src="https://gitee.com/leesmile/image-host/raw/master/images/202310201611606.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2024-01-02</div><div class="title">Java平台的特性</div></div></a></div><div><a href="/smile/2023/10/09/Java/%E5%AE%9A%E4%B9%89Java%E5%AE%9E%E4%BD%93%E7%B1%BB%E4%B8%BA%E4%BB%80%E4%B9%88%E8%A6%81%E5%AE%9E%E7%8E%B0Serializable%EF%BC%9F/" title="定义Java实体类为什么要实现Serializable？"><img class="cover" src="https://gitee.com/leesmile/image-host/raw/master/images/202310201611606.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2023-10-09</div><div class="title">定义Java实体类为什么要实现Serializable？</div></div></a></div><div><a href="/smile/2023/10/09/Java/VO%EF%BC%8CBO%EF%BC%8CPO%EF%BC%8CDO%EF%BC%8CDTO%E7%9A%84%E5%8C%BA%E5%88%AB/" title="VO，BO，PO，DO，DTO的区别"><img class="cover" src="https://gitee.com/leesmile/image-host/raw/master/images/202310201611606.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2023-10-09</div><div class="title">VO，BO，PO，DO，DTO的区别</div></div></a></div></div></div></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="author_top is-center"><div class="avatar-img"><img src="https://leesmile.gitee.io/smile/img/avatarImg.bmp" onerror="this.onerror=null;this.src='/smile/img/friend_404.gif'" alt="avatar"/></div><div class="author-info__name">Xuan</div><div class="author-info__description"></div></div><div class="card-info-data site-data is-center"><a href="/smile/archives/"><div class="headline">文章</div><div class="length-num">142</div></a><a href="/smile/tags/"><div class="headline">标签</div><div class="length-num">36</div></a><a href="/smile/categories/"><div class="headline">分类</div><div class="length-num">32</div></a></div><a id="card-info-btn" target="_blank" rel="noopener" href="https://github.com/xxxxxx"><i class="fab fa-github"></i><span>Follow Me</span></a></div><div class="card-widget card-announcement"><div class="item-headline"><i class="fas fa-bullhorn fa-shake"></i><span>公告</span></div><div class="announcement_content">This is my Blog</div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span><span class="toc-percentage"></span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#JDBC"><span class="toc-number">1.</span> <span class="toc-text">JDBC</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#JDBC%E6%98%AF%E4%BB%80%E4%B9%88"><span class="toc-number">1.0.0.1.</span> <span class="toc-text">JDBC是什么?</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#JDBC%E8%AE%BF%E9%97%AE%E6%95%B0%E6%8D%AE%E5%BA%93%E8%BF%87%E7%A8%8B"><span class="toc-number">1.0.0.2.</span> <span class="toc-text">JDBC访问数据库过程</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E5%B0%81%E8%A3%85JDBCUtil%E7%9A%84%E8%BF%87%E7%A8%8B"><span class="toc-number">1.0.0.3.</span> <span class="toc-text">封装JDBCUtil的过程</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E5%AE%9E%E7%8E%B0%E5%AF%B9%E6%95%B0%E6%8D%AE%E5%BA%93%E7%9A%84%E5%A2%9E%E5%88%A0%E6%94%B9%E6%9F%A5"><span class="toc-number">1.0.0.4.</span> <span class="toc-text">实现对数据库的增删改查</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E4%BD%BF%E7%94%A8%E6%95%B0%E6%8D%AE%E5%BA%93%E4%BA%8B%E5%8A%A1"><span class="toc-number">1.0.0.5.</span> <span class="toc-text">使用数据库事务</span></a></li></ol></li></ol></li></ol></li></ol></div></div><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item"><a class="thumbnail" href="/smile/2024/04/08/%E4%B8%8D%E5%90%8C%E8%A7%92%E5%BA%A6%E5%87%BA%E5%8F%91%E5%8E%BB%E9%9C%80%E6%B1%82%E6%B2%9F%E9%80%9A%E9%97%AE%E9%A2%98/" title="不同角度出发去需求沟通问题"><img src="https://gitee.com/leesmile/image-host/raw/master/images/202310271509358.jpg" onerror="this.onerror=null;this.src='/smile/img/404.jpg'" alt="不同角度出发去需求沟通问题"/></a><div class="content"><a class="title" href="/smile/2024/04/08/%E4%B8%8D%E5%90%8C%E8%A7%92%E5%BA%A6%E5%87%BA%E5%8F%91%E5%8E%BB%E9%9C%80%E6%B1%82%E6%B2%9F%E9%80%9A%E9%97%AE%E9%A2%98/" title="不同角度出发去需求沟通问题">不同角度出发去需求沟通问题</a><time datetime="2024-04-08T07:55:46.000Z" title="发表于 2024-04-08 15:55:46">2024-04-08</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/smile/2024/04/01/%E4%BA%A7%E5%93%81%E5%95%86%E4%B8%9A%E8%AE%A1%E5%88%92%E6%96%B9%E5%90%91%E6%80%9D%E8%80%83/" title="产品商业计划方向思考"><img src="https://gitee.com/leesmile/image-host/raw/master/images/202310271509358.jpg" onerror="this.onerror=null;this.src='/smile/img/404.jpg'" alt="产品商业计划方向思考"/></a><div class="content"><a class="title" href="/smile/2024/04/01/%E4%BA%A7%E5%93%81%E5%95%86%E4%B8%9A%E8%AE%A1%E5%88%92%E6%96%B9%E5%90%91%E6%80%9D%E8%80%83/" title="产品商业计划方向思考">产品商业计划方向思考</a><time datetime="2024-04-01T07:55:46.000Z" title="发表于 2024-04-01 15:55:46">2024-04-01</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/smile/2024/03/28/%E5%85%AC%E5%8F%B8%E8%87%AA%E5%8A%A8%E5%8C%96%E6%B5%8B%E8%AF%95%E8%90%BD%E5%9C%B0%E7%9A%84%E9%9A%BE%E7%82%B9/" title="公司自动化测试落地的难点"><img src="https://gitee.com/leesmile/image-host/raw/master/images/202310271509358.jpg" onerror="this.onerror=null;this.src='/smile/img/404.jpg'" alt="公司自动化测试落地的难点"/></a><div class="content"><a class="title" href="/smile/2024/03/28/%E5%85%AC%E5%8F%B8%E8%87%AA%E5%8A%A8%E5%8C%96%E6%B5%8B%E8%AF%95%E8%90%BD%E5%9C%B0%E7%9A%84%E9%9A%BE%E7%82%B9/" title="公司自动化测试落地的难点">公司自动化测试落地的难点</a><time datetime="2024-03-28T07:55:46.000Z" title="发表于 2024-03-28 15:55:46">2024-03-28</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/smile/2024/03/22/%E5%BC%82%E6%AD%A5%E4%BB%BB%E5%8A%A1%E7%9A%84%E5%85%B3%E9%94%AE%E5%9C%A8%E4%BA%A4%E4%BA%92%E8%AE%BE%E8%AE%A1/" title="异步任务的体验关键在交互设计"><img src="https://gitee.com/leesmile/image-host/raw/master/images/202310271509358.jpg" onerror="this.onerror=null;this.src='/smile/img/404.jpg'" alt="异步任务的体验关键在交互设计"/></a><div class="content"><a class="title" href="/smile/2024/03/22/%E5%BC%82%E6%AD%A5%E4%BB%BB%E5%8A%A1%E7%9A%84%E5%85%B3%E9%94%AE%E5%9C%A8%E4%BA%A4%E4%BA%92%E8%AE%BE%E8%AE%A1/" title="异步任务的体验关键在交互设计">异步任务的体验关键在交互设计</a><time datetime="2024-03-22T07:55:46.000Z" title="发表于 2024-03-22 15:55:46">2024-03-22</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/smile/2024/03/11/Git%E5%B7%A5%E4%BD%9C%E6%B5%81/" title="Git工作流"><img src="https://gitee.com/leesmile/image-host/raw/master/images/202310261354386.jpg" onerror="this.onerror=null;this.src='/smile/img/404.jpg'" alt="Git工作流"/></a><div class="content"><a class="title" href="/smile/2024/03/11/Git%E5%B7%A5%E4%BD%9C%E6%B5%81/" title="Git工作流">Git工作流</a><time datetime="2024-03-11T07:55:46.000Z" title="发表于 2024-03-11 15:55:46">2024-03-11</time></div></div></div></div></div></div></main><footer id="footer"><div id="footer-wrap"><div class="copyright">&copy;2020 - 2024 By Xuan</div><div class="framework-info"><span>框架 </span><a target="_blank" rel="noopener" href="https://hexo.io">Hexo</a><span class="footer-separator">|</span><span>主题 </span><a target="_blank" rel="noopener" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a></div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><button id="go-up" type="button" title="回到顶部"><span class="scroll-percent"></span><i class="fas fa-arrow-up"></i><span id="percent">0<span>%</span></span></button><button id="go-down" type="button" title="直达底部" onclick="btf.scrollToDest(document.body.scrollHeight, 500)"><i class="fas fa-arrow-down"></i></button></div></div><div><script src="/smile/js/utils.js"></script><script src="/smile/js/main.js"></script><script src="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox/fancybox.umd.min.js"></script><div class="js-pjax"></div><script async src="https://cdn1.tianli0.top/npm/vue@2.6.14/dist/vue.min.js"></script><script async src="https://cdn1.tianli0.top/npm/element-ui@2.15.6/lib/index.js"></script><script defer src="/js/cursor.js"></script><script async src="//npm.elemecdn.com/pace-js@1.2.4/pace.min.js"></script><script defer src="https://npm.elemecdn.com/jquery@latest/dist/jquery.min.js"></script><script defer data-pjax src="/js/cat.js"></script><script defer data-pjax src="/js/readPercent.js"></script><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div><!-- hexo injector body_end start --> <script data-pjax>if(document.getElementById('recent-posts') && (location.pathname ==='/'|| '/' ==='all')){
    var parent = document.getElementById('recent-posts');
    var child = '<div class="recent-post-item" style="width:100%;height: auto"><div id="catalog_magnet"><a class="magnet_link_more"  href="http://leesmile.gitee.io/smile/categories" style="flex:1;text-align: center;margin-bottom: 10px;">查看更多...</a></div></div>';
    console.log('已挂载magnet')
    parent.insertAdjacentHTML("afterbegin",child)}
     </script><style>#catalog_magnet{flex-wrap: wrap;display: flex;width:100%;justify-content:space-between;padding: 10px 10px 0 10px;align-content: flex-start;}.magnet_item{flex-basis: calc(50% - 5px);background: #87CEFA;margin-bottom: 10px;border-radius: 8px;transition: all 0.2s ease-in-out;}.magnet_item:hover{background: #00FFFF}.magnet_link_more{color:#555}.magnet_link{color:black}.magnet_link:hover{color:white}@media screen and (max-width: 600px) {.magnet_item {flex-basis: 100%;}}.magnet_link_context{display:flex;padding: 10px;font-size:16px;transition: all 0.2s ease-in-out;}.magnet_link_context:hover{padding: 10px 20px;}</style>
    <style></style><script data-pjax>
  function butterfly_footer_beautify_injector_config(){
    var parent_div_git = document.getElementById('footer-wrap');
    var item_html = '<div id="workboard"></div><p id="ghbdages"><a class="github-badge" target="_blank" href="https://hexo.io/" style="margin-inline:5px" data-title="博客框架为Hexo_v6.2.0" title=""><img src="https://img.shields.io/badge/Frame-Hexo-blue?style=flat&amp;logo=hexo" alt=""/></a><a class="github-badge" target="_blank" href="https://butterfly.js.org/" style="margin-inline:5px" data-title="主题版本Butterfly_v4.3.1" title=""><img src="https://img.shields.io/badge/Theme-Butterfly-6513df?style=flat&amp;logo=bitdefender" alt=""/></a><a class="github-badge" target="_blank" href="https://gitee.com/" style="margin-inline:5px" data-title="本站项目由Gitee托管" title=""><img src="https://img.shields.io/badge/Source-Github-d021d6?style=flat&amp;logo=GitHub" alt=""/></a><a class="github-badge" target="_blank" href="http://creativecommons.org/licenses/by-nc-sa/4.0/" style="margin-inline:5px" data-title="本站采用知识共享署名-非商业性使用-相同方式共享4.0国际许可协议进行许可" title=""><img src="https://img.shields.io/badge/Copyright-BY--NC--SA%204.0-d42328?style=flat&amp;logo=Claris" alt=""/></a></p>';
    console.log('已挂载butterfly_footer_beautify')
    parent_div_git.insertAdjacentHTML("beforeend",item_html)
    }
  var elist = 'null'.split(',');
  var cpage = location.pathname;
  var epage = 'all';
  var flag = 0;

  for (var i=0;i<elist.length;i++){
    if (cpage.includes(elist[i])){
      flag++;
    }
  }

  if ((epage ==='all')&&(flag == 0)){
    butterfly_footer_beautify_injector_config();
  }
  else if (epage === cpage){
    butterfly_footer_beautify_injector_config();
  }
  </script><script async src="https://npm.elemecdn.com/hexo-butterfly-footer-beautify@1.0.0/lib/runtime.js"></script><!-- hexo injector body_end end --></body></html>